home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d7 / lanuts.arc / LOGOUT.C < prev    next >
Text File  |  1991-10-30  |  6KB  |  194 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <dos.h>
  5. #include <direct.h>
  6. #include <conio.h>
  7.  
  8. #include "lantasti.h"
  9.  
  10. #define DOS 0x21
  11. #define NETBIOS 0x5C
  12. #define DELIM "+, "
  13.  
  14. /* structure to allow easy access to both segment and offset portions of
  15.    far pointers */
  16. #define LIST_SIZE 50
  17. #define NAME_SIZE 20
  18. typedef struct LIST {
  19.          int  num_servers;
  20.         char server[LIST_SIZE][NAME_SIZE];
  21.            } LIST;    
  22.            
  23. /* definitions to save typing time */
  24. #define C_SERVER list->server[i % list->num_servers]
  25.  
  26. /* getstring ********************************************************************
  27.  Get a string from the console -- takes a pointer to a string buffer, the 
  28.  longest permissible length and two switches. The empty switch determines
  29.  whether or not the user is allowed to enter an empty string. If TRUE, he
  30.  can, if FALSE, he must enter something.  The shown switch determines 
  31.  whether or not input is echoed to the screen, TRUE if echoed, FALSE if
  32.  invisible
  33. *****************************************************************************/
  34. void getstring(prompt,buffer,length,empty,shown) 
  35.   char *prompt,*buffer;
  36.   int length,empty,shown;
  37. {
  38.   fprintf(stdout,"%s",prompt);
  39.   fgets(buffer,length,stdin);
  40.   if (buffer[strlen(buffer) - 1] == '\n') buffer[strlen(buffer) - 1] = 0;
  41.   while (!(strlen(buffer) || empty)) {
  42.     fprintf(stdout,"%s",prompt);
  43.     fgets(buffer,length,stdin);
  44.     if (buffer[strlen(buffer) - 1] == '\n') buffer[strlen(buffer) - 1] = 0;
  45.   }
  46. }
  47.  
  48. /* error ********************************************************************
  49.  
  50. *****************************************************************************/
  51. void error(code,message)
  52.   int code;
  53.   char *message;
  54. {
  55.   char *ptr;
  56.   
  57.   if (code) {
  58.     ptr = get_error_text(code);
  59.     puts(ptr);
  60.   }
  61.   else puts(message);
  62. }
  63.  
  64. /* get_active_servers ********************************************************************
  65.  
  66. *****************************************************************************/
  67. void get_active_servers(list)
  68.   LIST *list;
  69. {
  70.   char buffer[17];
  71.   int index,result;
  72.   
  73.   index = 0;
  74.   result = get_active_server(buffer,index);
  75.   while (result) {
  76.     strcpy(list->server[list->num_servers++],buffer);
  77.     if (list->num_servers >= LIST_SIZE) {
  78.       puts("Warning: Too many servers.  Only the first 50 can be used.");
  79.       break;
  80.     }
  81.     result = get_active_server(buffer,++index);
  82.   }
  83. }
  84.  
  85. /* process_server_list ********************************************************************
  86.  
  87. *****************************************************************************/
  88. void process_server_list(string,list)
  89.   char *string;
  90.   LIST *list;
  91. {
  92.   char *ptr;
  93.   
  94.   ptr = strtok(string,DELIM);
  95.   
  96.   while (ptr !=NULL) {
  97.     if (!strcmp(ptr,"/HELP")) {
  98.       puts("LOGOUT utility for LANtastic -- Copyright 1989 by SoftMagic, Inc.");
  99.       puts("All rights reserved.  LANtastic is a trademark of Artisoft, Inc.\n");
  100.       puts("Usage: LOGOUT <server list> [/OPTIONS]");
  101.       puts("  A question mark in the list causes the program to prompt the user");
  102.       puts("  for input.  LOGOUT with no arguments will log you out of all");
  103.       puts("  active servers.\n");
  104.       puts("Available options are:");
  105.       puts("/HELP - display this documentation");
  106.       exit(0);
  107.       break;
  108.     }
  109.     if (*ptr == '*') {
  110.       list->num_servers = 0;
  111.       get_active_servers(list);
  112.       break;
  113.     }
  114.     else {
  115.       strcpy(list->server[list->num_servers++],ptr);
  116.     }
  117.  
  118.     if (list->num_servers >= LIST_SIZE ) {
  119.       puts("Warning: Too many servers.  Only the first 50 will be used.");
  120.       break;
  121.     }
  122.     ptr = strtok(NULL," ,");
  123.   }
  124.  
  125. /* if no servers are given, log out of everything */
  126.   if (list->num_servers == 0) get_active_servers(list);
  127. }
  128.   
  129. /* scan_command_line ********************************************************************
  130.  
  131. *****************************************************************************/
  132. scan_command_line(argc,argv,list)
  133.   int argc;
  134.   char *argv[];
  135.   LIST *list;
  136. {
  137.   int i;
  138.   char buffer[1];
  139.  
  140.   buffer[0] = 0;
  141.   list->num_servers = 0;
  142.   if (argc < 2) process_server_list(buffer,list);
  143.   
  144.   for (i = 1;i < argc; i++) {
  145.     strupr(argv[i]);
  146.     process_server_list(argv[i],list);
  147.   }
  148. }
  149.  
  150. /* do_login ********************************************************************
  151.  
  152. *****************************************************************************/
  153. int do_logout(list)
  154.   LIST *list;
  155. {
  156.   int result,i;
  157.   char logout_buffer[128];
  158.   
  159.   for (i = 0; i < list->num_servers; i++) {
  160.  
  161. /* see if we've got any "?"s in the list */
  162.     if (C_SERVER[0] == '?') {
  163.       getstring("Server: ",logout_buffer,128,FALSE,TRUE);
  164.       list->num_servers = i;
  165.       process_server_list(logout_buffer,list);
  166.     }
  167.     sprintf(logout_buffer,"\\\\%s",C_SERVER);
  168.     logout(logout_buffer);
  169.   }
  170. }
  171.  
  172. /* main ********************************************************************
  173.  
  174. *****************************************************************************/
  175. int main(argc,argv)
  176.   int argc;
  177.   char *argv[];
  178. {
  179.   LIST  list;             /*server, user and password lists*/    
  180.   int serverno;             /*index into serverlist*/
  181.  
  182.   #ifdef SHAREWARE
  183.   puts("LOGOUT utility for LANtastic -- Copyright 1989 by SoftMagic, Inc.");
  184.   puts("All rights reserved.  Thanks for trying this unregistered Shareware edition!\n");
  185. #endif  
  186.   
  187.   scan_command_line(argc,argv,&list);  
  188.   
  189.   if (list.num_servers > 0) do_logout(&list);
  190.   else error(FALSE,"You are not logged in to any servers.");
  191.   
  192.   return(0);
  193.  
  194. }